<?php

namespace iBrand\Component\Goods\Repositories\Eloquent;

use iBrand\Component\Goods\Models\GoodsProduct;
use iBrand\Component\Goods\Repositories\GoodsProductRepository;
use Prettus\Repository\Eloquent\BaseRepository;

class GoodsProductRepositoryEloquent extends BaseRepository implements GoodsProductRepository
{
    public function model()
    {
        return GoodsProduct::class;
    }

    public function getProductBySku($sku)
    {
        return $this->with('goods')->findWhere(['sku' => $sku, 'is_show' => 1])->first();
    }

    public function getProductByCode($code)
    {
        return $this->with('goods')->whereHas('goods', function ($query) use ($code) {
            return $query = $query->where('goods_no', 'like', '%' . $code . '%');
        })->get();
    }
}